package com.cdtye.itps.cms.jpbs;

import com.cdtye.itps.cms.service.job.SyncDataJobBrainService;
import com.cdtye.itps.cms.service.job.SyncDataJobService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

@Slf4j
@Component
@Controller
@EnableScheduling
public class SyncDataJobClient {
    @Autowired
    private SyncDataJobService syncDataJobService;

    @Autowired
    private SyncDataJobBrainService syncDataJobBrainService;

    /**
     * 检测缺陷数据同步--交大光芒
     *
     * @return
     */
    @XxlJob("getDefectInfosHandlerJdgm")//String param
    //@Scheduled(cron = "0 0/42 22 * * ?")
    public ReturnT<String> getDefectInfosHandlerJdgm(String param) {
        try {
            syncDataJobService.processDefectInfos();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行检测缺陷导入任务异常");
            XxlJobLogger.log(e);
            log.error("执行检测缺陷导入任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 检测缺陷数据同步--从 cms 转换到tmis
     *
     * @return
     */
    @XxlJob("getDefectFromCms2Tmis")
    public ReturnT<String> getDefectFromCms2Tmis(String param) {
        try {
            syncDataJobService.distributeTmisDefectInfos();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行检测缺陷贴源数据导入Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行检测缺陷贴源数据导入Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--字典 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDictionaryFromTmis2Brain")
    public ReturnT<String> getDictionaryFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDictionary();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据字典Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础字典Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--部门 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDeptFromTmis2Brain")
    public ReturnT<String> getDeptFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDept();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据部门Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础数据部门Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--线路 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getSeclineFromTmis2Brain")
    public ReturnT<String> getSeclineFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisSecline();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据线路Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础数据线路Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--行别 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDirectionFromTmis2Brain")
    public ReturnT<String> getDirectionFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDirection();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据行别Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础行别Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--区站 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getSiteFromTmis2Brain")
    public ReturnT<String> getSiteFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisSite();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据区站Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础数据区站Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--线路区站 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getLineSiteFromTmis2Brain")
    public ReturnT<String> getLineSiteFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisLineSite();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据线路区站Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础线路区站Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--部门区站 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDeptSiteFromTmis2Brain")
    public ReturnT<String> getDeptSiteFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDeptSite();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据部门区站Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础部门区站Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--隧道 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getTunnelFromTmis2Brain")
    public ReturnT<String> getTunnelFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisTunnel();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据隧道Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础隧道Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--隧道 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getAnchorFromTmis2Brain")
    public ReturnT<String> getAnchorFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisAnchor();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据锚段Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础锚段Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--支柱 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getPillarFromTmis2Brain")
    public ReturnT<String> getPillarFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisPillar();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据支柱Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础支柱Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--支柱设备 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDevicePillarsFromTmis2Brain")
    public ReturnT<String> getDevicePillarsFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDevicePillars();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据支柱设备Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础支柱设备Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--设备 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDeviceFromTmis2Brain")
    public ReturnT<String> getDeviceFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDevice();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据设备Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础设备Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--设备分类 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDeviceclassFromTmis2Brain")
    public ReturnT<String> getDeviceclassFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDeviceclass();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据设备分类Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础设备分类Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--设备周期 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getDeviceClassPeriodFromTmis2Brain")
    public ReturnT<String> getDeviceClassPeriodFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisDeviceClassPeriod();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据设备周期Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础设备周期Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 基础数据同步--检测周期 -- 从 tmis 转换到大脑brain
     *
     * @return
     */
    @XxlJob("getPeriodManageFromTmis2Brain")
    public ReturnT<String> getPeriodManageFromTmis2Brain(String param) {
        try {
            syncDataJobBrainService.distributeTmisPeriodManage();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("执行基础数据检测周期Tmis任务异常");
            XxlJobLogger.log(e);
            log.error("执行基础检测周期Tmis任务异常", e);
            return ReturnT.FAIL;
        }
    }
}
